package com.fox.hiring.company.dao;

import java.io.IOException;
import java.sql.ResultSet;

import javax.servlet.ServletException;

import com.fox.hiring.common.DBObject;
import com.fox.hiring.common.util.DBUtil;
import com.fox.hiring.company.entity.CompanyEntity;

/**
 * Company Dao
 * 
 * @author fox.
 * @since 2016年2月26日
 */
public class CompanyDao {

	/**
	 * 登录
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	public CompanyEntity login(String code, String password) {
		CompanyEntity company = null;
		String sql = "SELECT * FROM company WHERE code=? AND password=?";
		DBObject dbObject = null;
		try {
			dbObject = DBUtil.executeQuery(sql, code, password);
			ResultSet resultSet = dbObject.getResultSet();
			while (resultSet.next()) {
				company = new CompanyEntity();
				company.setId(resultSet.getInt("id"));
				company.setName(resultSet.getString("name"));
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(dbObject);
		}
		return company;
	}
}
